package com.fin.zw.intelligentbot.entity;


import com.fin.zw.intelligentbot.enums.UserStatus;
import lombok.Data;
import org.hibernate.annotations.Table;

import javax.persistence.*;
import java.util.Date;
import java.util.Set;

@Entity
@Table(appliesTo = "account",comment = "账号信息管理")
@Data
public class Account extends BaseEntity{

    @Column(columnDefinition = "varchar(20) COMMENT '登录用户'")
    private String name;

    @Column(columnDefinition = "varchar(100) COMMENT '密码'")
    private String password;

    @Column(columnDefinition = "varchar(20) COMMENT '状态'")
    @Enumerated(EnumType.STRING)
    private UserStatus userStatus;

    @Column(columnDefinition = "datetime COMMENT '最后一次登录时间'")
    private Date latestTime;

    @Column(columnDefinition = "varchar(50) COMMENT '最后一次登录ip'")
    private String latestIp;

    @Column(columnDefinition = "int(4) COMMENT '错误次数'")
    private Integer errorCount = 0;

    @Column(columnDefinition = "datetime COMMENT '锁定时间'")
    private Date lockTime;

    @Column(columnDefinition = "varchar(100) COMMENT '登录token'")
    private String token;

    @Column(columnDefinition = "datetime COMMENT 'token更新时间'")
    private Date tokenTime;

    @ManyToMany(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER)
    @JoinTable(name = "account_role", joinColumns = @JoinColumn(name = "account_id"), inverseJoinColumns = @JoinColumn(name = "role_id"))
    private Set<RoleInfo> roleInfoSet;
}
